// 导入axios模块
import request from '@/utils/request'

// 登陆相关api

// 登录请求
export const login = ({ username, password }) => {
  return request.post('/api/login', {
    username,
    password
  })
}
// 注册相关api

// 注册请求
export const register = ({ username, password, repassword }) => {
  return request.post('/api/reg', {
    username,
    password,
    repassword
  })
}

// 用户信息相关api

/**
 * 获取-用户基础资料
 * @returns Promise对象
 */
export const getUserInfoAPI = () => {
  return request({
    url: '/my/userinfo'
  })
}

// 更新-用户基础资料
export const changeUserInfoAPI = ({ id, nickname, email }) => {
  return request.put('/my/userinfo', {
    id,
    nickname,
    email
  })
}

// 重置密码
export const changePassWordAPI = ({ old_pwd, new_pwd, re_pwd }) => {
  return request.patch('/my/updatepwd', {
    old_pwd,
    new_pwd,
    re_pwd
  })
}

// 更新用户头像
export const changeAvatarAPI = ({ avatar }) => {
  console.log('1')
  console.log(avatar)
  return request.patch('/my/update/avatar', {
    avatar
  })
}

// 侧边栏相关api
/**
 * 获取-侧边栏菜单数据
 * @returns Promise对象
 */
export const getMenusAPI = () => {
  return request({
    url: '/my/menus'
  })
}
